package com.type.dao;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.annotation.Resource;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import com.type.vo.ProductVO;

@Repository("productDAO")
public class ProductDAO {

	@Resource(name="sqlMapClientTemplate")
	private SqlMapClientTemplate sqlmap;
	
	public ProductVO selectProductByName(String name) {
		ProductVO temp= new ProductVO();
		temp = (ProductVO) sqlmap.queryForObject("product.selectProductByName", name);
		
		return temp;
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<ProductVO> selectProductList() throws SQLException{
		return (ArrayList<ProductVO>) sqlmap.queryForList("product.selectProductList");
	}
	
	public void insertProduct(ProductVO p) throws SQLException {
		sqlmap.insert("product.registerProduct", p);
	}
	
	public void deleteProduct(int id) throws SQLException {
		sqlmap.delete("product.deleteProduct", id);
	}
	
	public void updateProduct(ProductVO p) throws SQLException {
		sqlmap.update("product.updateProduct", p);
	}
}
